package com.knowledge.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;

import com.knowledge.common.annotation.Log;
import com.knowledge.common.core.controller.BaseController;
import com.knowledge.common.core.domain.AjaxResult;
import com.knowledge.common.enums.BusinessType;
import com.knowledge.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledge.business.domain.SysMessage;
import com.knowledge.business.service.ISysMessageService;
import com.knowledge.common.core.page.TableDataInfo;

/**
 * 人与AI对话消息Controller
 *
 * @author zhaoyk
 * @date 2025-09-26
 */
@RestController
@RequestMapping("/business/message")
public class SysMessageController extends BaseController {
    @Autowired
    private ISysMessageService sysMessageService;

/**
 * 查询人与AI对话消息列表
 */
//@RequiresPermissions("business:message:list")
@GetMapping("/list")
    public TableDataInfo list(SysMessage sysMessage) {
        startPage();
        List<SysMessage> list = sysMessageService.selectSysMessageList(sysMessage);
        return getDataTable(list);
    }

    /**
     * 导出人与AI对话消息列表
     */
    //@RequiresPermissions("business:message:export")
    @Log(title = "人与AI对话消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMessage sysMessage) {
        List<SysMessage> list = sysMessageService.selectSysMessageList(sysMessage);
        ExcelUtil<SysMessage> util = new ExcelUtil<SysMessage>(SysMessage. class);
        util.exportExcel(response, list, "人与AI对话消息数据");
    }

    /**
     * 获取人与AI对话消息详细信息
     */
    //@RequiresPermissions("business:message:query")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId) {
        return AjaxResult.success(sysMessageService.getById(messageId));
    }

    /**
     * 新增人与AI对话消息
     */
    //@RequiresPermissions("business:message:add")
    @Log(title = "人与AI对话消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMessage sysMessage) {
        return toAjax(sysMessageService.save(sysMessage));
    }

    /**
     * 修改人与AI对话消息
     */
    //@RequiresPermissions("business:message:edit")
    @Log(title = "人与AI对话消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMessage sysMessage) {
        return toAjax(sysMessageService.updateById(sysMessage));
    }

    /**
     * 删除人与AI对话消息
     */
    //@RequiresPermissions("business:message:remove")
    @Log(title = "人与AI对话消息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds) {
        return toAjax(sysMessageService.removeByIds(Arrays.asList(messageIds)));
    }
}
